<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/1/17
 * Time: 14:33
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\api\model\mysql;

use app\common\model\TimeModel;

class MallUser extends TimeModel
{
    /**
     * @param string $openid
     * @param string $field
     * @return array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserByList(string $openid = '',string $field='*'){
        return $this
            ->field($field)
            ->where('openid',$openid)
            ->find();
    }

    /**
     * @param string $id
     * @param string $field
     * @return array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserById(string $id = '',string $field='*'){
        return $this
            ->field($field)
            ->where('id',$id)
            ->find();
    }

    /**
     * 获取下级会员数
     * @param $id
     * @return int
     */
    public function  getMemCount($id){
        return $this->field('*')->where("parent_id",$id)->count();
    }


}